<?php
/**
*	作者：信呼开发团队(雨中磐石)
*	官网：http://www.rockoa.com
*	文件信息
*/
class fileClassModel extends Model
{
	
	/**
	*	保存新的文件
	*/
	public function editcall($filenum, $filepath, $newext)
	{
		$optname = $this->rock->jm->base64decode($this->rock->get('optname'));
		$optid   = (int)$this->rock->get('optid','0');
		
		$frs 	 = $this->getone("`filenum`='$filenum'");
		$fileext = $frs['fileext'];
		$fileid  = $frs['id'];
		
		$filesize 			= filesize($filepath);
		$filesizecn 		= $this->rock->formatsize($filesize);
		$fname  			= $frs['filename'];
		
		$insar = $frs;
		unset($insar['id']);
		$insar['oid'] 		= $fileid;
		$insar['filenum'] 	= $this->db->ranknum('[Q]file','filenum', 8);
		$insar['onlynum'] 	= md5($filepath.rand(1000,9999));
		$insar['filename'] 	= str_replace('.'.$frs['fileext'].'','(备份).'.$fileext.'', $fname);
		$insar['optid']  	 = $optid;
		$insar['optname']  	 = $optname;
		$this->insert($insar); //复制一条
		
		
		$fext	= c('upfile')->getext($fname);
		if($newext != $fext){
			$uare['filename']= str_replace('.'.$fext.'','.'.$newext.'', $fname);
		}
		$uare['filepath'] 	 = $filepath;
		$uare['pdfpath']  	 = '';
		$uare['filepathout'] = '';
		$uare['filesize']    = $filesize;
		$uare['fileext']     = $newext;
		$uare['filesizecn']  = $filesizecn;
		$uare['optdt']  	 = $this->rock->now;
		$uare['editid']  	 = $optid;
		$uare['editname']  	 = $optname;
		
		$this->update($uare, $fileid);

		if(getconfig('qcloudCos_autoup')){
			c('reim')->push('qcloudCos,run',array('fileid'=>$fileid));
		}
		
		//异步回调
		c('reim')->push('editfile,anaycall',array('fileid'=>$fileid));
		
		return 'ok';
	}
	
	/**
	*	是否是图片
	*/
	public function isimg($ext)
	{
		$imgs = ',jpg,png,gif,jpeg,bmp,';
		return contain($imgs,','.$ext.',');
	}
}